var app = getApp();
Page({
  data: {
    dataList: [{
        key: "comingList",
        path: "/movieComingList",
        title: "即将上映"
      },
      {
        key: "movieList",
        path: "/movieOnInfoList",
        title: "正在热映"
      },
      {
        key: "cinemas",
        path: "/cinemaList",
        title: "影院"
      }
    ],
    classList: [],
    currentCity: [],
    num: 0
  },
  toPath(e) {
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + e.currentTarget.dataset.id,
    })
  },
  onLoad() {
    this.setData({
      currentCity: app.globalData.currentCity
    })
    this.getDetailData(0);
  },

  getSelect(e) {
    this.getDetailData(e.detail.index)
  },
  getDetailData(index) {
    var dataList = this.data.dataList;
    // var cityId= app.globalData.currentCity.id, //获取Id,就像id一样配置在cityId位置
    var num = index;
    wx.request({
      url: `http://39.97.33.178/api/${dataList[index].path}?cityId=` + app.globalData.currentCity.id,
      success: (res) => {
        var data = res.data.data;
        var classList = data[dataList[index].key];
        if (index !== 2) {
          classList.map((item) => {
            item.img = item.img.replace("w.h", "66.94");
          })
        }
        this.setData({
          num,
          classList
        })
        console.log(classList)
      }
    })
  },

  toCity() {
    wx.navigateTo({
      url: '/pages/city/city',
    })
  }
})